package com.project.finance.exchange.controller;

import com.project.finance.common.po.TbExchange;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.exchange.service.ExchangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/*
*   汇率换算表
*
*/
@RestController
@RequestMapping("/api")
@Slf4j
public class ExchangeController {

    @Autowired
    private ExchangeService exchangeService;



    @RequestMapping(value="/exchanges",method = RequestMethod.GET)
    public Result select(@RequestParam("money") int money,
                         @RequestParam("country1") String controy1,
                         @RequestParam("country2") String controy2
                         ){
        exchangeService.selectByCountry();

        return null;
    }

    /*查询所有信息*/
//    @RequestMapping(value = "/exchange",method = RequestMethod.GET)
//    public Result selectAll(){
//        List<TbExchange> tbExchanges = exchangeService.selectAll();
//
//        return ResultGenerator.apiSuccess(tbExchanges);
//    }

    /*修改汇率*/
    @RequestMapping(value = "/exchange",method = RequestMethod.PUT)
    public Result update(@RequestBody TbExchange tbExchange){
        log.info(String.valueOf(tbExchange));
        int i = exchangeService.update(tbExchange);
        if (i>0){
            return ResultGenerator.apiSuccess("ok");
        }else {
            return ResultGenerator.apiError("error");
        }

    }
    //分页
    @RequestMapping(value = "/exchange",method = RequestMethod.GET)
    public ResultMsg listExchangeByPageCondition(@RequestParam("pageSize")int pageSize,
                                                 @RequestParam("pageNum")int pageNum){
        ResultMsg resultMsg = exchangeService.listExchangeByPage(pageSize, pageNum);
        resultMsg.setCode(0);
        return resultMsg;
    }
}
